// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.pageno = 0;
        this.skillArr = [];
        this.aniMap = {};
        for(var key in _SKILL){
            if(!this.aniMap[_SKILL[key].ani]){
                this.skillArr.push(key);
                this.aniMap[_SKILL[key].ani]=1;
            }
        }
        this.refresh();
        this.initButton();
    },

    initButton:function(){
        this.node.getChildByName('xia').on(cc.Node.EventType.TOUCH_START,function(){
            this.pageno++;
            if(this.pageno>=this.skillArr.length){
                this.pageno=0;
            }
            this.refresh();
        }, this);

        this.node.getChildByName('shang').on(cc.Node.EventType.TOUCH_START,function(){
            this.pageno++;
            if(this.pageno<0){
                this.pageno=this.skillArr.length-1;
            }
            this.refresh();
        }, this);
    },

    refresh:function(){

        var aniName = this.skillArr[this.pageno];

        var skillConf = _SKILL[aniName];

        this.node.getChildByName('skillname').getComponent(cc.Label).string = aniName+"["+skillConf.ani+"]";

        var aniNode = this.node.getChildByName('model');

        var framearr = _GRM.getSkillFrame(skillConf.ani);

        aniNode.getComponent(cc.Animation).addClip(_GRM.createAniClipTime(framearr,aniName,cc.WrapMode.Loop,8));
        aniNode.getComponent(cc.Animation).play(aniName);

    }

    // update (dt) {},
});
